<template>
  <div class="lhx-demo-container">
    <div class="lhx-demo-header">
      <h1>LHX 聊天模块演示</h1>
      <p>点击下方按钮体验不同角色的聊天功能</p>
    </div>
    
    <div class="lhx-demo-grid">
      <!-- 患者角色演示 -->
      <div class="lhx-demo-card">
        <div class="lhx-demo-icon">🏥</div>
        <h3>患者聊天列表</h3>
        <p>查看可以聊天的医生列表<br/>（基于就诊记录）</p>
        <div class="lhx-demo-users">
          <label>
            <input type="radio" v-model="lhxSelectedPatient" value="p001" />
            患者张三 (p001)
          </label>
          <label>
            <input type="radio" v-model="lhxSelectedPatient" value="p002" />
            患者李四 (p002)
          </label>
        </div>
        <button @click="lhxGoToPatientChat" class="lhx-demo-btn lhx-patient-btn">
          进入患者聊天列表
        </button>
      </div>
      
      <!-- 医生角色演示 -->
      <div class="lhx-demo-card">
        <div class="lhx-demo-icon">👨‍⚕️</div>
        <h3>医生聊天列表</h3>
        <p>查看向自己发起聊天的患者<br/>（患者主动联系）</p>
        <div class="lhx-demo-users">
          <label>
            <input type="radio" v-model="lhxSelectedDoctor" value="d001" />
            张医生 (d001) - 内科
          </label>
          <label>
            <input type="radio" v-model="lhxSelectedDoctor" value="d002" />
            李医生 (d002) - 外科
          </label>
          <label>
            <input type="radio" v-model="lhxSelectedDoctor" value="d003" />
            王医生 (d003) - 妇科
          </label>
        </div>
        <button @click="lhxGoToDoctorChat" class="lhx-demo-btn lhx-doctor-btn">
          进入医生聊天列表
        </button>
      </div>
      
      <!-- 直接聊天演示 -->
      <div class="lhx-demo-card">
        <div class="lhx-demo-icon">💬</div>
        <h3>直接进入聊天</h3>
        <p>跳过列表页面<br/>直接进入聊天窗口</p>
        <div class="lhx-demo-rooms">
          <button 
            v-for="room in lhxDemoRooms" 
            :key="room.roomId"
            @click="lhxGoToChat(room)"
            class="lhx-room-btn"
          >
            {{ room.label }}
          </button>
        </div>
      </div>
    </div>
    
 
    
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { useRouter } from 'vue-router';

const router = useRouter();

// 选中的用户
const lhxSelectedPatient = ref('p001');
const lhxSelectedDoctor = ref('d001');

// 演示聊天房间
const lhxDemoRooms = ref([
  {
    roomId: 'p001_d001',
    label: '患者张三 ↔ 张医生',
    patientId: 'p001',
    patientName: '患者张三',
    doctorId: 'd001',
    doctorName: '张医生'
  },
  {
    roomId: 'p002_d002',
    label: '患者李四 ↔ 李医生',
    patientId: 'p002',
    patientName: '患者李四',
    doctorId: 'd002',
    doctorName: '李医生'
  }
]);

/**
 * 进入患者聊天列表
 */
function lhxGoToPatientChat() {
  // 临时设置当前用户信息到localStorage，实际项目中应该通过登录系统管理
  const userData = {
    userId: lhxSelectedPatient.value,
    userType: 'patient',
    name: lhxSelectedPatient.value === 'p001' ? '患者张三' : '患者李四'
  };
  
  localStorage.setItem('lhx_current_user', JSON.stringify(userData));
  
  router.push('/lhx-patient-chat');
}

/**
 * 进入医生聊天列表
 */
function lhxGoToDoctorChat() {
  // 临时设置当前用户信息到localStorage
  const doctorNames = {
    'd001': '张医生',
    'd002': '李医生',
    'd003': '王医生'
  };
  
  const userData = {
    userId: lhxSelectedDoctor.value,
    userType: 'doctor',
    name: doctorNames[lhxSelectedDoctor.value as keyof typeof doctorNames]
  };
  
  localStorage.setItem('lhx_current_user', JSON.stringify(userData));
  
  router.push('/lhx-doctor-chat');
}

/**
 * 直接进入聊天窗口
 */
function lhxGoToChat(room: any) {
  // 默认以患者身份进入聊天
  router.push({
    path: '/lhx-chat',
    query: {
      lhxRoomId: room.roomId,
      lhxDoctorId: room.doctorId,
      lhxDoctorName: room.doctorName,
      lhxUserId: room.patientId,
      lhxUserType: 'patient',
      lhxUserName: room.patientName
    }
  });
}
</script>

<style scoped>
/* 移动端响应式样式 */
.lhx-demo-container {
  width: 100%;
  padding: 16px;
  background: #f8f9fa;
  min-height: 100vh;
  min-height: 100dvh; /* 动态视窗高度 */
}

.lhx-demo-header {
  text-align: center;
  margin-bottom: 24px;
  padding: 24px 16px;
  background: white;
  border-radius: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.lhx-demo-header h1 {
  color: #2c3e50;
  margin-bottom: 12px;
  font-size: 24px;
  font-weight: 600;
}

.lhx-demo-header p {
  color: #666;
  font-size: 15px;
  margin: 0;
  line-height: 1.5;
}

.lhx-demo-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 24px;
}

/* 平板及以上使用网格布局 */
@media (min-width: 768px) {
  .lhx-demo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
  }
}

.lhx-demo-card {
  background: white;
  padding: 24px 20px;
  border-radius: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  text-align: center;
  transition: transform 0.2s;
}

.lhx-demo-card:active {
  transform: scale(0.98);
}

.lhx-demo-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.lhx-demo-card h3 {
  color: #2c3e50;
  margin-bottom: 8px;
  font-size: 18px;
  font-weight: 600;
}

.lhx-demo-card p {
  color: #666;
  margin-bottom: 16px;
  line-height: 1.5;
  font-size: 14px;
}

.lhx-demo-users {
  margin-bottom: 16px;
  text-align: left;
}

.lhx-demo-users label {
  display: flex;
  align-items: center;
  margin-bottom: 12px;
  cursor: pointer;
  padding: 12px;
  border-radius: 8px;
  transition: background-color 0.2s;
  min-height: 44px; /* 移动端最小触摸目标 */
  font-size: 15px;
}

.lhx-demo-users label:active {
  background: #f8f9fa;
}

.lhx-demo-users input {
  margin-right: 12px;
  transform: scale(1.2); /* 放大单选框 */
}

.lhx-demo-btn {
  width: 100%;
  padding: 14px 24px;
  border: none;
  border-radius: 24px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 48px; /* 移动端最小触摸目标 */
}

.lhx-patient-btn {
  background: #3498db;
  color: white;
}

.lhx-patient-btn:active {
  background: #2980b9;
  transform: scale(0.98);
}

.lhx-doctor-btn {
  background: #27ae60;
  color: white;
}

.lhx-doctor-btn:active {
  background: #219a52;
  transform: scale(0.98);
}

.lhx-demo-rooms {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.lhx-room-btn {
  padding: 14px 16px;
  background: #9b59b6;
  color: white;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 14px;
  font-weight: 500;
  min-height: 48px; /* 移动端最小触摸目标 */
  text-align: left;
}

.lhx-room-btn:active {
  background: #8e44ad;
  transform: scale(0.98);
}

.lhx-demo-info {
  background: white;
  padding: 20px 16px;
  border-radius: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.lhx-demo-info h3 {
  color: #2c3e50;
  margin-bottom: 16px;
  text-align: center;
  font-size: 18px;
  font-weight: 600;
}

.lhx-info-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* 平板及以上使用网格布局 */
@media (min-width: 768px) {
  .lhx-info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
  }
}

.lhx-info-item {
  padding: 16px;
  background: #f8f9fa;
  border-radius: 12px;
}

.lhx-info-item h4 {
  color: #2c3e50;
  margin-bottom: 10px;
  font-size: 16px;
  font-weight: 600;
}

.lhx-info-item ul {
  margin: 0;
  padding-left: 16px;
}

.lhx-info-item li {
  margin-bottom: 6px;
  line-height: 1.5;
  font-size: 14px;
}

.lhx-info-item strong {
  color: #3498db;
}
</style>